using NUnit.Framework;
using ValidationFramework.Specifications.Tests.Helpers;
using ValidationFramework.Specifications;

namespace ValidationFramework.Specifications.Tests
{
	public class IsValidAttributeTests
	{
		[TestFixture]
		public class CreateSpecification
		{
			[Test]
			public void Should_Create_Default_IsValidSpec()
			{
				// Arrange
				var mockInfoDescriptor = new FakeReflectionInfo();
				var expectedSpec = new IsValidSpec();

				// Act
				var attribute = new IsValidAttribute();
				var validator = (IsValidSpec)attribute.CreateSpecification(mockInfoDescriptor);
				
				// Assert
				Assert.IsTrue(validator.IsEquivalentTo(expectedSpec));
			}

			[Test]
			public void Should_Create_Non_Default_IsValidSpec_When_Member_Ruleset_Is_Set()
			{
				// Arrange
				var mockInfoDescriptor = new FakeReflectionInfo();
				var expectedSpec = new IsValidSpec();

				// Act
				var attribute = new IsValidAttribute() { MemberRuleSet = "NonDefaultRuleSet" };
				var validator = (IsValidSpec)attribute.CreateSpecification(mockInfoDescriptor);

				// Assert
				Assert.IsFalse(validator.IsEquivalentTo(expectedSpec));
			}

			[Test]
			public void Should_Passthrough_Spec_Properties()
			{
				// Arrange
				var mockInfoDescriptor = new FakeReflectionInfo();
				var expectedSpec = new IsValidSpec() { UseTargetErrorMessages = true, TargetRuleSet = "MemberRuleSet" };

				// Act
				var attribute = new IsValidAttribute() { UseMemberErrorMessages = true, MemberRuleSet = "MemberRuleSet" };
				var validator = (IsValidSpec)attribute.CreateSpecification(mockInfoDescriptor);

				// Assert
				Assert.IsTrue(validator.IsEquivalentTo(expectedSpec));
			}
		}
	}
}